<!DOCTYPE html>
<html lang="zh-CN">
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="beans.Employee" %>
<%@ page import="service.EmployeeService" %>
<%
    // 从会话中获取用户信息（使用您现有的登录系统）
    Employee employee = (Employee) session.getAttribute("user");
    String role = (String) session.getAttribute("role");

    // 如果不是员工角色或者没有登录，重定向到登录页面
    if (employee == null || (!"employee".equals(role) && !"finance".equals(role) && !"driverLeader".equals(role))) {
        response.sendRedirect("login.jsp");
        return;
    }

    // 如果需要刷新员工信息，从数据库重新获取
    String refresh = request.getParameter("refresh");
    if ("true".equals(refresh)) {
        EmployeeService employeeService = new EmployeeService();
        Employee refreshedEmployee = employeeService.getEmployeeByID(employee.getEmployeeID());
        if (refreshedEmployee != null) {
            employee = refreshedEmployee;
            session.setAttribute("user", employee); // 更新session中的用户信息
        }
    }

    // 获取消息参数，用于显示操作结果
    String message = request.getParameter("message");
%>

<head>
    <meta charset="UTF-8">
    <title>公司用车管理系统（用车员工）</title>
    <style>
        /* 保持原有的CSS样式 */
        body {
            margin: 0;
            padding: 0;
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background: #f6f6f6;
        }

        .header {
            background: #183a8a;
            color: #fff;
            font-size: 2rem;
            font-weight: bold;
            padding: 10px 0 10px 10px;
            letter-spacing: 2px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .header-right {
            display: flex;
            align-items: center;
            margin-right: 30px;
            font-size: 1rem;
        }

        .user-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: #fff;
            color: #183a8a;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
            margin-right: 10px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }

        .user-info {
            margin-right: 20px;
            color: #fff;
        }

        .bell-icon {
            font-size: 1.3rem;
            margin-right: 20px;
            color: #fff;
            cursor: pointer;
            transition: transform 0.2s;
        }

        .bell-icon:hover {
            transform: scale(1.1);
        }

        .logout {
            color: #fff;
            text-decoration: none;
            margin-left: 10px;
            font-size: 1rem;
            transition: color 0.2s;
        }

        .logout:hover {
            color: #a8c5ff;
        }

        .container {
            display: flex;
            height: calc(100vh - 56px);
        }

        .sidebar {
            width: 220px;
            background: #183a8a;
            display: flex;
            flex-direction: column;
            padding-top: 10px;
            box-shadow: 2px 0 8px rgba(24, 58, 138, 0.05);
        }

        .menu-item {
            color: #fff;
            padding: 18px 0 18px 32px;
            font-size: 1.15rem;
            cursor: pointer;
            border-left: 5px solid transparent;
            transition: background 0.2s, border 0.2s, transform 0.2s;
            text-decoration: none;
            display: block;
        }

        .menu-item.active,
        .menu-item:hover {
            background: #2450a7;
            border-left: 5px solid #fff;
            font-weight: bold;
            box-shadow: 0 4px 8px rgba(24, 58, 138, 0.10);
            transform: translateX(2px);
        }

        .main-content {
            flex: 1;
            background: #f6f6f6;
            padding: 30px;
            overflow-y: auto;
        }

        /* 个人中心卡片样式 */
        .profile-card {
            background: #ffffff;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            max-width: 700px;
            margin: 0 auto;
            overflow: hidden;
        }

        .profile-header {
            background: #183a8a;
            color: white;
            padding: 30px;
            display: flex;
            align-items: center;
        }

        .profile-avatar {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            background: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 3rem;
            margin-right: 20px;
            color: #183a8a;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        }

        .profile-title {
            font-size: 1.8rem;
            font-weight: bold;
            margin-bottom: 5px;
        }

        .profile-subtitle {
            font-size: 1rem;
            color: rgba(255, 255, 255, 0.8);
        }

        .profile-body {
            padding: 30px;
        }

        .profile-field {
            display: grid;
            grid-template-columns: 120px 1fr;
            gap: 20px;
            align-items: center;
            padding: 15px 0;
            border-bottom: 1px solid #f0f0f0;
        }

        .profile-field:last-child {
            border-bottom: none;
        }

        .field-label {
            font-weight: 500;
            color: #666;
            font-size: 1rem;
        }

        .field-value {
            font-size: 1rem;
            padding: 8px 12px;
            border-radius: 6px;
            background: #f8f9fa;
            transition: background 0.2s;
        }

        .profile-actions {
            display: flex;
            justify-content: flex-end;
            padding: 20px 30px;
            background: #f8f9fa;
            border-top: 1px solid #f0f0f0;
        }

        .btn {
            background: #2450a7;
            color: #fff;
            font-size: 1rem;
            cursor: pointer;
            border: none;
            border-radius: 6px;
            padding: 10px 25px;
            transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
            text-decoration: none;
            box-shadow: 0 4px 12px rgba(36, 80, 167, 0.2);
            display: flex;
            align-items: center;
        }

        .btn:hover {
            background: #1a4080;
            transform: translateY(-2px);
            box-shadow: 0 6px 16px rgba(36, 80, 167, 0.3);
        }

        .btn:active {
            transform: translateY(0);
            box-shadow: 0 2px 8px rgba(36, 80, 167, 0.2);
        }

        /* 模态框样式 */
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            justify-content: center;
            align-items: center;
        }

        .modal-content {
            background-color: #fff;
            border-radius: 12px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
            width: 500px;
            max-width: 90%;
            position: relative;
            transform: scale(0.9);
            opacity: 0;
            transition: transform 0.3s ease, opacity 0.3s ease;
        }

        .modal.active .modal-content {
            transform: scale(1);
            opacity: 1;
        }

        .modal-header {
            padding: 25px 30px;
            border-bottom: 1px solid #eee;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .modal-title {
            font-size: 1.5rem;
            font-weight: bold;
            color: #183a8a;
        }

        .close-modal {
            font-size: 1.8rem;
            color: #aaa;
            cursor: pointer;
            transition: color 0.2s;
        }

        .close-modal:hover {
            color: #333;
        }

        .modal-body {
            padding: 30px;
        }

        .modal-body .form-group {
            margin-bottom: 25px;
        }

        .modal-body label {
            display: block;
            margin-bottom: 10px;
            font-weight: 500;
            color: #333;
        }

        .modal-body input,
        .modal-body select {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 1rem;
            box-sizing: border-box;
            transition: border-color 0.2s, box-shadow 0.2s;
        }

        .modal-body input:focus,
        .modal-body select:focus {
            outline: none;
            border-color: #2450a7;
            box-shadow: 0 0 0 3px rgba(36, 80, 167, 0.15);
        }

        .modal-footer {
            padding: 20px 30px;
            border-top: 1px solid #eee;
            display: flex;
            justify-content: flex-end;
            gap: 15px;
        }

        .modal-btn {
            padding: 12px 25px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 1rem;
            transition: background 0.2s, transform 0.2s;
            font-weight: 500;
        }

        .modal-btn-primary {
            background-color: #2450a7;
            color: white;
        }

        .modal-btn-primary:hover {
            background-color: #1a4080;
            transform: translateY(-2px);
        }

        .modal-btn-secondary {
            background-color: #f1f1f1;
            color: #333;
        }

        .modal-btn-secondary:hover {
            background-color: #e1e1e1;
            transform: translateY(-2px);
        }

        /* 通知样式 */
        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            background-color: #4CAF50;
            color: white;
            padding: 12px 20px;
            border-radius: 6px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            z-index: 1000;
            transform: translateX(150%);
            opacity: 0;
            transition: transform 0.3s ease, opacity 0.3s ease;
        }

        .notification.error {
            background-color: #f44336;
        }

        .notification.show {
            transform: translateX(0);
            opacity: 1;
        }

        @media (max-width: 900px) {
            .sidebar {
                width: 120px;
            }

            .menu-item {
                padding: 18px 0 18px 15px;
                text-align: center;
                font-size: 1rem;
            }

            .main-content {
                padding: 15px;
            }

            .profile-card {
                border-radius: 8px;
            }

            .profile-header {
                padding: 20px;
            }

            .profile-avatar {
                width: 60px;
                height: 60px;
                font-size: 2rem;
            }

            .profile-title {
                font-size: 1.5rem;
            }

            .profile-body {
                padding: 20px;
            }

            .profile-field {
                grid-template-columns: 100px 1fr;
                gap: 15px;
                padding: 12px 0;
            }

            .field-label,
            .field-value {
                font-size: 0.95rem;
            }

            .profile-actions {
                padding: 15px 20px;
            }

            .btn {
                padding: 8px 20px;
                font-size: 0.95rem;
            }

            .modal-content {
                border-radius: 8px;
            }

            .modal-header,
            .modal-body,
            .modal-footer {
                padding: 20px;
            }

            .modal-title {
                font-size: 1.3rem;
            }

            .modal-body .form-group {
                margin-bottom: 20px;
            }

            .modal-btn {
                padding: 10px 20px;
                font-size: 0.95rem;
            }
        }
    </style>
</head>

<body>
<div class="header">
    <div>欢迎登录公司用车管理系统（用车员工）</div>
    <div class="header-right">
        <div class="user-icon">👤</div>
        <div class="user-info">账号：<%= employee.getEmployeeID() %></div>
        <div class="bell-icon">🔔</div>
        <a href="${pageContext.request.contextPath}/LogoutServlet" class="logout">退出登录</a>
    </div>
</div>
<div class="container">
    <div class="sidebar">
        <a class="menu-item" href="shouye.jsp">
            系统首页
        </a>
        <a class="menu-item" href="shenqing.jsp">
            申请用车
        </a>
        <a class="menu-item" href="jindu.jsp">
            申请进度
        </a>
        <a class="menu-item" href="lishi.jsp">
            历史订单
        </a>
        <a class="menu-item active" href="#">
            个人中心
        </a>
    </div>
    <div class="main-content">
        <!-- 显示操作结果消息 -->
        <% if(message != null && !message.isEmpty()) { %>
        <div id="notification" class="notification show">
            <%= message %>
        </div>
        <% } %>

        <!-- 美化后的个人信息卡片 -->
        <div class="profile-card">
            <div class="profile-header">
                <div class="profile-avatar">👤</div>
                <div>
                    <div class="profile-title"><%= employee.getEmployeeName() %></div>
                    <div class="profile-subtitle"><%= employee.getEmployeeID() %> · <%= employee.getPosition() %></div>
                </div>
            </div>
            <div class="profile-body">
                <div class="profile-field">
                    <div class="field-label">姓名</div>
                    <div class="field-value"><%= employee.getEmployeeName() %></div>
                </div>
                <div class="profile-field">
                    <div class="field-label">员工账号</div>
                    <div class="field-value"><%= employee.getEmployeeID() %></div>
                </div>
                <div class="profile-field">
                    <div class="field-label">密码</div>
                    <div class="field-value">
                        <span style="letter-spacing: 2px">••••••••</span>
                    </div>
                </div>
                <div class="profile-field">
                    <div class="field-label">性别</div>
                    <div class="field-value"><%= employee.getGender() != null ? employee.getGender() : "未设置" %></div>
                </div>
                <div class="profile-field">
                    <div class="field-label">电话</div>
                    <div class="field-value"><%= employee.getPhoneNumber() != null ? employee.getPhoneNumber() : "未设置" %></div>
                </div>
                <div class="profile-field">
                    <div class="field-label">邮箱</div>
                    <div class="field-value"><%= employee.getEmail() != null ? employee.getEmail() : "未设置" %></div>
                </div>
                <div class="profile-field">
                    <div class="field-label">职务</div>
                    <div class="field-value"><%= employee.getPosition() != null ? employee.getPosition() : "未设置" %></div>
                </div>
                <div class="profile-field">
                    <div class="field-label">入职日期</div>
                    <div class="field-value"><%= employee.getHireDate() != null ? new java.text.SimpleDateFormat("yyyy-MM-dd").format(employee.getHireDate()) : "未设置" %></div>
                </div>
            </div>
            <div class="profile-actions">
                <button type="button" class="btn" id="editButton">
                    修改信息
                </button>
            </div>
        </div>
    </div>
</div>

<!-- 模态框 -->
<div class="modal" id="editModal">
    <div class="modal-content">
        <div class="modal-header">
            <div class="modal-title">修改个人信息</div>
            <div class="close-modal">&times;</div>
        </div>
        <div class="modal-body">
            <form id="editForm" action="${pageContext.request.contextPath}/employee" method="post">
                <input type="hidden" name="action" value="update">
                <input type="hidden" name="employeeID" value="<%= employee.getEmployeeID() %>">
                <input type="hidden" name="departmentID" value="<%= employee.getDepartmentID() %>">
                <input type="hidden" name="employeeName" value="<%= employee.getEmployeeName() %>">
                <input type="hidden" name="position" value="<%= employee.getPosition() %>">
                <input type="hidden" name="hireDate" value="<%= employee.getHireDate() != null ? new java.text.SimpleDateFormat("yyyy-MM-dd").format(employee.getHireDate()) : "" %>">
                <input type="hidden" name="gender" value="<%= employee.getGender() %>">

                <div class="form-group">
                    <label>员工账号：</label>
                    <input type="text" value="<%= employee.getEmployeeID() %>" disabled>
                </div>
                <div class="form-group">
                    <label>姓名：</label>
                    <input type="text" value="<%= employee.getEmployeeName() %>" disabled>
                </div>
                <div class="form-group">
                    <label>密码：</label>
                    <input type="password" name="password" value="<%= employee.getPassword() %>" required>
                </div>
                <div class="form-group">
                    <label>性别：</label>
                    <select disabled>
                        <option value="男" <%= "男".equals(employee.getGender()) ? "selected" : "" %>>男</option>
                        <option value="女" <%= "女".equals(employee.getGender()) ? "selected" : "" %>>女</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>电话：</label>
                    <input type="tel" name="phoneNumber" value="<%= employee.getPhoneNumber() != null ? employee.getPhoneNumber() : "" %>" required pattern="[0-9]{11}">
                </div>
                <div class="form-group">
                    <label>邮箱：</label>
                    <input type="email" name="email" value="<%= employee.getEmail() != null ? employee.getEmail() : "" %>">
                </div>
                <div class="form-group">
                    <label>职务：</label>
                    <input type="text" value="<%= employee.getPosition() %>" disabled>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="modal-btn modal-btn-secondary" id="cancelEdit">取消</button>
            <button type="button" class="modal-btn modal-btn-primary" id="saveEdit">保存</button>
        </div>
    </div>
</div>

<script>
    // 获取DOM元素
    const editButton = document.getElementById('editButton');
    const modal = document.getElementById('editModal');
    const closeModal = document.querySelector('.close-modal');
    const cancelEdit = document.getElementById('cancelEdit');
    const saveEdit = document.getElementById('saveEdit');
    const editForm = document.getElementById('editForm');
    const notification = document.getElementById('notification');

    // 如果有通知，3秒后自动隐藏
    if (notification) {
        setTimeout(() => {
            notification.classList.remove('show');
            setTimeout(() => {
                notification.style.display = 'none';
            }, 300);
        }, 3000);
    }

    // 显示模态框
    editButton.addEventListener('click', () => {
        modal.style.display = 'flex';
        // 添加active类以触发动画
        setTimeout(() => {
            modal.classList.add('active');
        }, 10);
    });

    // 关闭模态框
    function hideModal() {
        modal.classList.remove('active');
        setTimeout(() => {
            modal.style.display = 'none';
        }, 300);
    }

    closeModal.addEventListener('click', hideModal);
    cancelEdit.addEventListener('click', hideModal);

    // 点击模态框外部关闭
    modal.addEventListener('click', (e) => {
        if (e.target === modal) {
            hideModal();
        }
    });

    // 保存修改
    saveEdit.addEventListener('click', () => {
        // 表单验证
        const passwordInput = editForm.querySelector('input[name="password"]');
        const phoneInput = editForm.querySelector('input[name="phoneNumber"]');

        if (!passwordInput.value.trim()) {
            alert('密码不能为空！');
            passwordInput.focus();
            return;
        }

        if (!phoneInput.value.trim()) {
            alert('电话不能为空！');
            phoneInput.focus();
            return;
        }

        if (!/^[0-9]{11}$/.test(phoneInput.value.trim())) {
            alert('请输入正确的11位手机号码！');
            phoneInput.focus();
            return;
        }

        // 提交表单
        editForm.submit();
    });

    // 阻止模态框内容的点击事件冒泡
    modal.querySelector('.modal-content').addEventListener('click', (e) => {
        e.stopPropagation();
    });
</script>
</body>

</html>